<nav class="navbar navbar-default" role="navigation">
  <div class="container-fluid">   
    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header">
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="<?php echo site_url('welcome'); ?>"><span class="glyphicon glyphicon-home"></span></a>
    </div>
    <!-- Collect the nav links, forms, and other content for toggling -->
    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
      <ul class="nav navbar-nav">
         <?php
            foreach($menu as $row)
            {
                $madanhmuc = $row['madanhmuc'];
                $tendanhmuc = $row['tendanhmuc'];
                $danhmuccon = array();
                $danhmuccon = $row['danhmuccon'];   
                $countDanhMucCon = count($danhmuccon);           
                if($madanhmuc != 'trangchu')
                {
                    if($currentItem == $madanhmuc)
                    {    
                        if($countDanhMucCon > 0)
                        {                        
                            echo "<li class=\"dropdown\" class='active'>";
                            echo "<a href=\"#\" class=\"dropdown-toggle\" data-toggle=\"dropdown\">$tendanhmuc<b class=\"caret\"></b></a>";
                            echo "<ul class=\"dropdown-menu\">";                            
                            for($k = 0 ; $k < $countDanhMucCon; $k++)
                            {
                                $madanhmuc_con = $danhmuccon[$k]['madanhmuc_con'];
                                $tendanhmuc_con = $danhmuccon[$k]['tendanhmuc'];                                    
                                echo  "<li><a href='". site_url($madanhmuc . '?page=' . $tendanhmuc_con . '&madanhmuc=' . $madanhmuc_con . '&madanhmuc_cha=' . $madanhmuc . '&number=1') ."'>$tendanhmuc_con</a></li>";  
                                if($k < $countDanhMucCon - 1) echo "<li class='divider'></li>";
                            }
                            echo "</ul></li>";                     
                        }
                        else
                        {
                            echo "<li class='active'><a href='". site_url($madanhmuc) ."'>$tendanhmuc</a></li>"; 
                        }                        
                    }
                    else
                    {
                         
                        if($countDanhMucCon > 0)
                        {                        
                            echo "<li class=\"dropdown\">";
                            echo "<a href=\"#\" class=\"dropdown-toggle\" data-toggle=\"dropdown\">$tendanhmuc<b class=\"caret\"></b></a>";
                            echo "<ul class=\"dropdown-menu\">";                            
                            for($k = 0 ; $k < $countDanhMucCon; $k++)
                            {
                                $madanhmuc_con = $danhmuccon[$k]['madanhmuc_con'];
                                $tendanhmuc_con = $danhmuccon[$k]['tendanhmuc'];                                    
                                echo  "<li><a href='". site_url($madanhmuc . '?page=' . $tendanhmuc_con .'&madanhmuc=' . $madanhmuc_con . '&madanhmuc_cha=' . $madanhmuc . '&number=1') ."'>$tendanhmuc_con</a></li>";  
                                if($k < $countDanhMucCon - 1) echo "<li class='divider'></li>";
                            }
                            echo "</ul></li>";                     
                        }
                        else
                        {
                            echo "<li><a href='". site_url($madanhmuc) ."'>$tendanhmuc</a></li>";    
                        }
                    }                      
                }         
            }              
        ?>
      </ul>
    </div><!-- /.navbar-collapse -->
  </div><!-- /.container-fluid -->
</nav>